package ru.nsu.effel.actions;

import java.util.Iterator;
import java.util.List;

import ru.nsu.effel.persistence.Account;
import ru.nsu.effel.persistence.AccountManager;
import ru.nsu.effel.persistence.ConnectionBid;
import ru.nsu.effel.persistence.ConnectionBidManager;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;

public class ClientActionBean implements ActionBean {

	ActionBeanContext context;
	
	public ActionBeanContext getContext() {
		return context;
	}

	public void setContext(ActionBeanContext context) {
		this.context = context;
	}
	
	public String getStatus() {
		AccountManager am = AccountManager.getInstance();
		Account account = am.getAccountById((Integer)getContext().getRequest().getSession().getAttribute("accountId"));
		ConnectionBidManager cbm = ConnectionBidManager.getInstance();
		List<ConnectionBid> bids = cbm.getAllConnectionBids();
		for (Iterator<ConnectionBid> iter = bids.iterator(); iter.hasNext();) {
			ConnectionBid bid = iter.next();
			if (bid.getUsername().equals(account.getLogin())) {
				String status = null;
				if (1 == bid.getBidStatus()) {
					status = "Wait fot fitter";
				} else if (2 == bid.getBidStatus()){
					status = "In progress";
				} else if (3 == bid.getBidStatus()) {
					status = "Done";
				}				
				return new String("Your bid is in progress: " + status);
			}
		}
		return new String("You are connected");
	}

}
